# Contributor: fossdd <fossdd@pwned.life>
# Maintainer: fossdd <fossdd@pwned.life>
pkgname=mautrix-gvoice
pkgver=0.1.0
pkgrel=0
pkgdesc="Matrix-Google Voice puppeting bridge"
url="https://docs.mau.fi/bridges/go/gvoice/"
arch="all"
license="AGPL-3.0-or-later"
makedepends="
	go
	olm-dev
	sqlite-dev
	"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/mautrix/gvoice/archive/v$pkgver.tar.gz
	mautrix-gvoice.initd
	mautrix-gvoice.confd
	"
builddir="$srcdir/gvoice-$pkgver"
options="net"

export GOFLAGS="$GOFLAGS -tags=libsqlite3"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

case "$CARCH" in
	armhf|armv7|x86)
		options="$options !check";; # https://github.com/mautrix/gvoice/issues/2
esac


build() {
	export CGO_CFLAGS="$CFLAGS"
	export CGO_LDFLAGS="$LDFLAGS"

	go build \
		-ldflags "-X main.Tag=$pkgver -X 'main.BuildTime=$(date -d @"$SOURCE_DATE_EPOCH" '+%b %_d %Y, %H:%M:%S')'" \
		./cmd/mautrix-gvoice

	./mautrix-gvoice -e
}

check() {
	go test -v ./...
}

package() {
	install -Dm755 mautrix-gvoice \
		-t "$pkgdir"/usr/bin/
	install -Dm644 config.yaml \
		-t "$pkgdir"/etc/mautrix-gvoice/

	install -Dm755 "$srcdir"/mautrix-gvoice.initd \
		"$pkgdir"/etc/init.d/mautrix-gvoice
	install -Dm644 "$srcdir"/mautrix-gvoice.confd \
		"$pkgdir"/etc/conf.d/mautrix-gvoice

	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}


sha512sums="
d88edb7f690c434532d9eefd20cd3d29e43d9bdac9dc4b259572d80608710e32b6cdf99303e583abccb20fa09dd4aeb0c1643fdd44f6501fa5f3af8a357f0f32  mautrix-gvoice-0.1.0.tar.gz
23bb2c8d81d944fae147880555a793a8ee5091027abef058efaeb33cecedf43fe3b68f164aa4d27eaafdeaccc23c6f853966c6570287276d71e45128c91814e6  mautrix-gvoice.initd
2a0ed15f3dfa6b79de5e0ec42dc28efbb828c5cd3234aadc8db5544c5046513d82a2627ba66d97426ceb97037e7b0039039ccbf7000f8e135942671b5764f3a7  mautrix-gvoice.confd
"
